Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/aws/aws-sdk…
Browse files Browse the repository at this point in the history
…-go-v2/config-1.19.1
  • Loading branch information
markphelps authored Oct 30, 2023
2 parents cf75740 + 8a19f7f commit bd9ce0c
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-tools-
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-tools-
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-tools-
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.17.0
github.com/redis/go-redis/v9 v9.2.0
github.com/redis/go-redis/v9 v9.2.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/redis/go-redis/v9 v9.0.0-rc.4/go.mod h1:Vo3EsyWnicKnSKCA7HhgnvnyA74wOA69Cd2Meli5mmA=
github.com/redis/go-redis/v9 v9.2.0 h1:zwMdX0A4eVzse46YN18QhuDiM4uf3JmkOB4VZrdt5uI=
github.com/redis/go-redis/v9 v9.2.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down
12 changes: 7 additions & 5 deletions internal/server/auth/method/github/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
storageMetadataGithubEmail = "io.flipt.auth.github.email"
storageMetadataGithubName = "io.flipt.auth.github.name"
storageMetadataGithubPicture = "io.flipt.auth.github.picture"
storageMetadataGithubSub = "io.flipt.auth.github.sub"
)

// Server is an Github server side handler.
Expand Down Expand Up @@ -135,17 +136,14 @@ func (s *Server) Callback(ctx context.Context, r *auth.CallbackRequest) (*auth.C
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
ID uint64 `json:"id,omitempty"`
}

if err := json.NewDecoder(userResp.Body).Decode(&githubUserResponse); err != nil {
return nil, err
}

metadata := map[string]string{
storageMetadataGithubEmail: githubUserResponse.Email,
storageMetadataGithubName: githubUserResponse.Name,
storageMetadataGithubPicture: githubUserResponse.AvatarURL,
}
metadata := map[string]string{}

if githubUserResponse.Name != "" {
metadata[storageMetadataGithubName] = githubUserResponse.Name
Expand All @@ -159,6 +157,10 @@ func (s *Server) Callback(ctx context.Context, r *auth.CallbackRequest) (*auth.C
metadata[storageMetadataGithubPicture] = githubUserResponse.AvatarURL
}

if githubUserResponse.ID != 0 {
metadata[storageMetadataGithubSub] = fmt.Sprintf("%d", githubUserResponse.ID)
}

clientToken, a, err := s.store.CreateAuthentication(ctx, &storageauth.CreateAuthenticationRequest{
Method: auth.Method_METHOD_GITHUB,
ExpiresAt: timestamppb.New(time.Now().UTC().Add(s.config.Session.TokenLifetime)),
Expand Down
3 changes: 2 additions & 1 deletion internal/server/auth/method/github/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestServer_Github(t *testing.T) {
MatchHeader("Accept", "application/vnd.github+json").
Get("/user").
Reply(200).
JSON(map[string]string{"name": "fliptuser", "email": "[email protected]", "avatar_url": "https://thispicture.com"})
JSON(map[string]any{"name": "fliptuser", "email": "[email protected]", "avatar_url": "https://thispicture.com", "id": 1234567890})

c, err := client.Callback(ctx, &auth.CallbackRequest{Code: "github_code"})
require.NoError(t, err)
Expand All @@ -134,6 +134,7 @@ func TestServer_Github(t *testing.T) {
storageMetadataGithubEmail: "[email protected]",
storageMetadataGithubName: "fliptuser",
storageMetadataGithubPicture: "https://thispicture.com",
storageMetadataGithubSub: "1234567890",
}, c.Authentication.Metadata)

gock.Off()
Expand Down
3 changes: 3 additions & 0 deletions internal/server/auth/method/oidc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
storageMetadataIDNameKey = "io.flipt.auth.oidc.name"
storageMetadataIDProfileKey = "io.flipt.auth.oidc.profile"
storageMetadataIDPictureKey = "io.flipt.auth.oidc.picture"
storageMetadataIDSubKey = "io.flipt.auth.oidc.sub"
)

// errProviderNotFound is returned when a provider is requested which
Expand Down Expand Up @@ -215,6 +216,7 @@ type claims struct {
Name *string `json:"name"`
Profile *string `json:"profile"`
Picture *string `json:"picture"`
Sub *string `json:"sub"`
}

func (c claims) addToMetadata(m map[string]string) {
Expand All @@ -228,6 +230,7 @@ func (c claims) addToMetadata(m map[string]string) {
set(storageMetadataIDNameKey, c.Name)
set(storageMetadataIDProfileKey, c.Profile)
set(storageMetadataIDPictureKey, c.Picture)
set(storageMetadataIDSubKey, c.Sub)

if c.Verified != nil {
m[storageMetadataIDEmailVerifiedKey] = fmt.Sprintf("%v", *c.Verified)
Expand Down
1 change: 1 addition & 0 deletions internal/server/auth/method/oidc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func testOIDCFlow(t *testing.T, ctx context.Context, tpAddr, clientAddress strin
"io.flipt.auth.oidc.provider": "google",
"io.flipt.auth.oidc.email": "[email protected]",
"io.flipt.auth.oidc.name": "Mark Phelps",
"io.flipt.auth.oidc.sub": "mark",
}, response.Authentication.Metadata)

// ensure expiry is set
Expand Down
5 changes: 4 additions & 1 deletion internal/server/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

const ipKey = "x-forwarded-for"
const (
ipKey = "x-forwarded-for"
subKey = "sub"
)

var _ auth.AuthenticationServiceServer = &Server{}

Expand Down
53 changes: 32 additions & 21 deletions ui/src/app/flags/Flag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,61 @@ import Modal from '~/components/Modal';
import MoreInfo from '~/components/MoreInfo';
import CopyToNamespacePanel from '~/components/panels/CopyToNamespacePanel';
import DeletePanel from '~/components/panels/DeletePanel';
import { copyFlag, deleteFlag, getFlag } from '~/data/api';
import { useError } from '~/data/hooks/error';
import { useAppDispatch } from '~/data/hooks/store';
import { useSuccess } from '~/data/hooks/success';
import { useTimezone } from '~/data/hooks/timezone';
import { FlagType, IFlag } from '~/types/Flag';
import { RootState } from '~/store';
import { FlagType } from '~/types/Flag';
import { classNames } from '~/utils/helpers';
import {
copyFlagAsync,
deleteFlagAsync,
fetchFlagAsync,
selectFlag
} from './flagsSlice';
import Rollouts from './rollouts/Rollouts';

export default function Flag() {
let { flagKey } = useParams();
const { inTimezone } = useTimezone();

const [flag, setFlag] = useState<IFlag | null>(null);
const [flagVersion, setFlagVersion] = useState(0);

const { setError, clearError } = useError();
const { setSuccess } = useSuccess();

const navigate = useNavigate();
const dispatch = useAppDispatch();

const namespaces = useSelector(selectNamespaces);
const namespace = useSelector(selectCurrentNamespace);
const readOnly = useSelector(selectReadonly);

const flag = useSelector((state: RootState) =>
selectFlag(state, namespace.key, flagKey || '')
);

const [showDeleteFlagModal, setShowDeleteFlagModal] = useState(false);
const [showCopyFlagModal, setShowCopyFlagModal] = useState(false);

const incrementFlagVersion = () => {
setFlagVersion(flagVersion + 1);
};

const tabs = [
{ name: 'Variants', to: '' },
{ name: 'Rules', to: 'rules' }
];

useEffect(() => {
if (!flagKey) return;
if (!namespace.key || !flagKey) return;

getFlag(namespace.key, flagKey)
.then((flag: IFlag) => {
setFlag(flag);
dispatch(fetchFlagAsync({ namespaceKey: namespace.key, key: flagKey }))
.unwrap()
.then(() => {
clearError();
})
.catch((err) => {
setError(err);
});
}, [flagVersion, flagKey, namespace.key, clearError, setError]);
}, [flagKey, namespace.key, clearError, setError]);

Check warning on line 74 in ui/src/app/flags/Flag.tsx

View workflow job for this annotation

GitHub Actions / Lint UI

React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array

if (!flag) return <Loading />;
if (!flag || flag.key != flagKey) return <Loading />;

return (
<>
Expand All @@ -84,7 +89,11 @@ export default function Flag() {
}
panelType="Flag"
setOpen={setShowDeleteFlagModal}
handleDelete={() => deleteFlag(namespace.key, flag.key)}
handleDelete={() =>
dispatch(
deleteFlagAsync({ namespaceKey: namespace.key, key: flag.key })
)
}
onSuccess={() => {
navigate(`/namespaces/${namespace.key}/flags`);
}}
Expand All @@ -104,9 +113,11 @@ export default function Flag() {
panelType="Flag"
setOpen={setShowCopyFlagModal}
handleCopy={(namespaceKey: string) =>
copyFlag(
{ namespaceKey: namespace.key, key: flag.key },
{ namespaceKey: namespaceKey, key: flag.key }
dispatch(
copyFlagAsync({
from: { namespaceKey: namespace.key, key: flag.key },
to: { namespaceKey: namespaceKey, key: flag.key }
})
)
}
onSuccess={() => {
Expand Down Expand Up @@ -182,7 +193,7 @@ export default function Flag() {
</MoreInfo>
</div>
<div className="mt-5 md:col-span-2 md:mt-0">
<FlagForm flag={flag} flagChanged={incrementFlagVersion} />
<FlagForm flag={flag} />
</div>
</div>
</div>
Expand Down Expand Up @@ -212,7 +223,7 @@ export default function Flag() {
</nav>
</div>
</div>
<Outlet context={{ flag, incrementFlagVersion }} />
<Outlet context={{ flag }} />
</>
)}
{flag.type === FlagType.BOOLEAN && <Rollouts flag={flag} />}
Expand Down
Loading

0 comments on commit bd9ce0c

Please sign in to comment.