Skip to content

Commit

Permalink
service: permission/accesskey (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamoto-febc committed Mar 24, 2022
1 parent 84f1cc5 commit ffdbcaf
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 0 deletions.
28 changes: 28 additions & 0 deletions permission/accesskey/create_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"github.com/sacloud/packages-go/validate"
)

type CreateRequest struct {
SiteId string `service:"-" validate:"required"`
PermissionId int64 `service:"-" validate:"required"`
}

func (req *CreateRequest) Validate() error {
return validate.New().Struct(req)
}
34 changes: 34 additions & 0 deletions permission/accesskey/create_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"context"

objectstorage "github.com/sacloud/object-storage-api-go"
v1 "github.com/sacloud/object-storage-api-go/apis/v1"
)

func (s *Service) Create(req *CreateRequest) (*v1.PermissionKey, error) {
return s.CreateWithContext(context.Background(), req)
}

func (s *Service) CreateWithContext(ctx context.Context, req *CreateRequest) (*v1.PermissionKey, error) {
if err := req.Validate(); err != nil {
return nil, err
}
client := objectstorage.NewPermissionOp(s.client)
return client.CreateAccessKey(ctx, req.SiteId, req.PermissionId)
}
29 changes: 29 additions & 0 deletions permission/accesskey/delete_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"github.com/sacloud/packages-go/validate"
)

type DeleteRequest struct {
SiteId string `service:"-" validate:"required"`
PermissionId int64 `service:"-" validate:"required"`
Id string `service:"-" validate:"required"` // リソースId
}

func (req *DeleteRequest) Validate() error {
return validate.New().Struct(req)
}
33 changes: 33 additions & 0 deletions permission/accesskey/delete_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"context"

objectstorage "github.com/sacloud/object-storage-api-go"
)

func (s *Service) Delete(req *DeleteRequest) error {
return s.DeleteWithContext(context.Background(), req)
}

func (s *Service) DeleteWithContext(ctx context.Context, req *DeleteRequest) error {
if err := req.Validate(); err != nil {
return err
}
client := objectstorage.NewPermissionOp(s.client)
return client.DeleteAccessKey(ctx, req.SiteId, req.PermissionId, req.Id)
}
26 changes: 26 additions & 0 deletions permission/accesskey/find_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import "github.com/sacloud/packages-go/validate"

type FindRequest struct {
SiteId string `service:"-" validate:"required"`
PermissionId int64 `service:"-" validate:"required"`
}

func (req *FindRequest) Validate() error {
return validate.New().Struct(req)
}
38 changes: 38 additions & 0 deletions permission/accesskey/find_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"context"

objectstorage "github.com/sacloud/object-storage-api-go"
v1 "github.com/sacloud/object-storage-api-go/apis/v1"
)

func (s *Service) Find(req *FindRequest) ([]*v1.PermissionKey, error) {
return s.FindWithContext(context.Background(), req)
}

func (s *Service) FindWithContext(ctx context.Context, req *FindRequest) ([]*v1.PermissionKey, error) {
if req == nil {
req = &FindRequest{}
}
if err := req.Validate(); err != nil {
return nil, err
}

client := objectstorage.NewPermissionOp(s.client)
return client.ListAccessKeys(ctx, req.SiteId, req.PermissionId)
}
29 changes: 29 additions & 0 deletions permission/accesskey/read_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"github.com/sacloud/packages-go/validate"
)

type ReadRequest struct {
SiteId string `service:"-" validate:"required"`
PermissionId int64 `service:"-" validate:"required"`
Id string `service:"-" validate:"required"` // リソースId
}

func (req *ReadRequest) Validate() error {
return validate.New().Struct(req)
}
34 changes: 34 additions & 0 deletions permission/accesskey/read_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import (
"context"

objectstorage "github.com/sacloud/object-storage-api-go"
v1 "github.com/sacloud/object-storage-api-go/apis/v1"
)

func (s *Service) Read(req *ReadRequest) (*v1.PermissionKey, error) {
return s.ReadWithContext(context.Background(), req)
}

func (s *Service) ReadWithContext(ctx context.Context, req *ReadRequest) (*v1.PermissionKey, error) {
if err := req.Validate(); err != nil {
return nil, err
}
client := objectstorage.NewPermissionOp(s.client)
return client.ReadAccessKey(ctx, req.SiteId, req.PermissionId, req.Id)
}
27 changes: 27 additions & 0 deletions permission/accesskey/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 The sacloud/object-storage-service-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package accesskey

import objectstorage "github.com/sacloud/object-storage-api-go"

// Service provides a high-level API of for Site
type Service struct {
client *objectstorage.Client
}

// New returns new service instance of Archive
func New(client *objectstorage.Client) *Service {
return &Service{client: client}
}
Loading

0 comments on commit ffdbcaf

Please sign in to comment.